package com.hlf.modules.wechat.service.impl;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.IdWorkerFactory;
import com.hlf.modules.base.service.impl.BaseServiceImpl;
import com.hlf.modules.wechat.mapper.UserOfficialMapper;
import com.hlf.modules.wechat.model.UserOfficial;
import com.hlf.modules.wechat.service.UserOfficialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 用户公众号关联服务层实现类
 * 
 * @author shuliangxing
 *
 * @date 2017年4月19日 下午3:34:13
 */
@Service
public class UserOfficialServiceImpl extends BaseServiceImpl<UserOfficial, UserOfficialMapper>
        implements UserOfficialService {

    @Autowired
    UserOfficialMapper mapper;

    @Override
    public void doSubscribe(Long userId, String officialAccountId) {
        UserOfficial userOfficial = new UserOfficial();
        userOfficial.setFollowStatus(Constants.IS_SUBSCRIBE);
        userOfficial.setId(IdWorkerFactory.nextId());
        userOfficial.setUserId(userId);
        userOfficial.setOfficialAccountId(officialAccountId);

        mapper.updateFollowStatus(Constants.IS_SUBSCRIBE, userId, officialAccountId);
    }

    @Override
    public void doUnSubscribe(Long userId, String officialAccountId) {
        mapper.updateFollowStatus(Constants.NO_SUBSCRIBE, userId, officialAccountId);
    }

    @Override
    public UserOfficial selectByOpenIdOffAccId(String openId, String officialAccountId) {
        return mapper.selectByOpenIdOffAccId(openId, officialAccountId);
    }

}
